import cn.xy.dao.TeacherMapper;
import cn.xy.pojo.Teacher;
import cn.xy.utils.MybatisUtils;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;

public class test {
    @Test
    public void test01(){
        //根据id查询teacher
        //数据库类名和实体类字段名不一致，所以是用resultMap手动映射结果集
        SqlSession sqlSession = MybatisUtils.getSqlSeesion();
        TeacherMapper mapper = sqlSession.getMapper(TeacherMapper.class);
        Teacher teacher = mapper.getTeacherById(1);
        System.out.println(teacher);
        sqlSession.close();
    }

    //使用limit分页
    @Test
    public void test02(){
        SqlSession sqlSeesion = MybatisUtils.getSqlSeesion();
        TeacherMapper mapper = sqlSeesion.getMapper(TeacherMapper.class);
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        map.put("startIndex",0);
        map.put("pageSize",2);
        List<Teacher> teacherList = mapper.getTeacherListByList(map);
        for (Teacher teacher : teacherList) {
            System.out.println(teacher);
        }

        sqlSeesion.close();
    }

    //使用rowBounds分页
    @Test
    public void test03(){
        SqlSession sqlSeesion = MybatisUtils.getSqlSeesion();

        RowBounds rowBounds = new RowBounds(0,2);
        List<Teacher> teacherList = sqlSeesion.selectList("cn.xy.dao.TeacherMapper.getTeacherListByRowBounds", null, rowBounds);
        for (Teacher teacher : teacherList) {
            System.out.println(teacher);
        }
        sqlSeesion.close();
    }
}
